﻿using eShop.Core;
using eShop.Web.Framework;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace eShop.Web.Admin.Models
{ /// <summary>
  /// 客户列表模型类
  /// </summary>
    public class CustomerListModel
    {
        /// <summary>
        /// 分页对象
        /// </summary>
        public PageModel PageModel { get; set; }
        /// <summary>
        /// 用户列表
        /// </summary>
        public DataTable CustomerList { get; set; }
        /// <summary>
        /// 客户编号
        /// </summary>
        public string EnCode { get; set; }
        /// <summary>
        /// 客户名称
        /// </summary>
        public string FullName { get; set; }
        /// <summary>
        /// 客户简称
        /// </summary>
        public string ShortName { get; set; }



        public string CustinDustryid { get; set; }
        public string CustTypeid { get; set; }
        public string CustLevelid { get; set; }
        public string CustDegreeid { get; set; }
        public string Regionid { get; set; }
        public string Contact { get; set; }
        public string Mobile { get; set; }
        public string Tel { get; set; }
        public string Fax { get; set; }
        public string Email { get; set; }
        public string CompanyAddress { get; set; }
        public string CompanySite { get; set; }
        public string TraceUserName { get; set; }
        public string Description { get; set; }

    }

    /// <summary>
    /// 客户模型类
    /// </summary>
    public class CustomerModel : IValidatableObject
    {
        public DataTable CusotmerList { get; set; }
        /// <summary>
        /// 客户编号
        /// </summary>
        [Required(ErrorMessage = "客户编号不能为空")]
        [StringLength(50, ErrorMessage = "客户编号长度不能大于50")]
        public string EnCode { get; set; }

        /// <summary>
        /// 客户全称
        /// </summary>
        [Required(ErrorMessage = "客户全称不能为空")]
        [StringLength(50, ErrorMessage = "客户全称长度不能大于50")]
        public string FullName { get; set; }


        /// <summary>
        /// 客户简称
        /// </summary>
        [Required(ErrorMessage = "客户简称不能为空")]
        [StringLength(50, ErrorMessage = "客户简称长度不能大于50")]
        public string ShortName { get; set; }



        /// <summary>
        /// 所属行业
        /// </summary>
        [DisplayName("所属行业")]
        public string CustinDustryid { get; set; }



        /// <summary>
        /// 客户类型
        /// </summary>
        [DisplayName("客户类型")]
        public string CustTypeid { get; set; }



        /// <summary>
        /// 客户等级
        /// </summary>
        [DisplayName("客户等级")]
        public string CustLevelid { get; set; }

        /// <summary>
        /// 客户程度
        /// </summary>
        [DisplayName("客户程度")]
        public string CustDegreeid { get; set; }


        /// <summary>
        /// 所在地
        /// </summary>
        [DisplayName("区域")]
        public int Regionid { get; set; }

        /// <summary>
        /// 联系人
        /// </summary>
        [DisplayName("联系人")]
        public string Contact { get; set; }
        /// <summary>
        /// 手机
        /// </summary>
        [Mobile]
        public string Mobile { get; set; }

        /// <summary>
        /// 电话
        /// </summary>
        [Mobile]
        public string Tel { get; set; }
        /// <summary>
        /// 邮箱
        /// </summary>
        [Email]
        [StringLength(50, ErrorMessage = "邮箱长度不能大于50")]
        public string Email { get; set; }

        [DisplayName("传真")]
        public string Fax { get; set; }

        [DisplayName("客户地址")]
        public string CompanyAddress { get; set; }


        [DisplayName("客户网址")]
        public string CompanySite { get; set; }


        [DisplayName("负责人")]
        public string TraceUserName { get; set; }


        [DisplayName("客户介绍")]
        public string Description { get; set; }

        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            List<ValidationResult> errorList = new List<ValidationResult>();

            if (!SecureHelper.IsSafeSqlString(FullName, false))
            {
                errorList.Add(new ValidationResult("名称中包含不安全的字符,请删除!", new string[] { "FullName" }));
            }

            if (!SecureHelper.IsSafeSqlString(Email, false))
            {
                errorList.Add(new ValidationResult("邮箱名中包含不安全的字符,请删除!", new string[] { "Email" }));
            }

            return errorList;
        }
    }

}
